/* GUI CONVERTED from arargl1.p (converter v1.76) Wed May 21 06:59:29 2003 */
/* arargl1.p - CREATE AR GENERAL LEDGER TRANSACTIONS FOR PAYMENTS            */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.57 $                                                         */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 6.0      LAST MODIFIED: 08/23/90   BY: MLB *D060*               */
/*                                   02/28/91   BY: afs *D387*               */
/*                                   03/12/91   BY: MLB *D360*               */
/*                                   05/02/91   BY: MLV *D595*               */
/*                                   05/31/91   BY; MLV *D667*               */
/*                                   11/06/91   BY: MLV *D915*               */
/* REVISION: 7.0      LAST MODIFIED: 10/28/91   BY: MLV *F028*               */
/*                                   02/18/92   BY: MLV *F200*               */
/*                                   02/26/92   by: jms *F239*               */
/* REVISION: 7.3      LAST MODIFIED: 03/17/93   BY: bcm *G834*               */
/*                                   06/29/93   BY: pcd *GC86*               */
/* REVISION: 7.4      LAST MODIFIED: 09/22/93   BY: bcm *H133*               */
/*                                   06/07/94   BY: pmf *FO67*               */
/*                                   08/09/94   by: pmf *FQ02*               */
/*                                   09/08/94   BY: bcm *H509*               */
/*                                   01/15/96   BY: mys *H0HN*               */
/* REVISION: 8.5      LAST MODIFIED: 01/13/95   by: ccc *J053*               */
/* REVISION: 8.6      LAST MODIFIED: 06/14/96   BY: BJL *K001*               */
/*                    LAST MODIFIED: 07/10/96   by: *G1ZP* Sanjay Patil      */
/* REVISION: 8.6      LAST MODIFIED: 08/12/97   BY: *J1X9* Samir Bavkar      */
/* REVISION: 8.6      LAST MODIFIED: 11/03/97   BY: *J24H* Irine D'mello     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 04/07/98   by: *L00K* rup               */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton      */
/* REVISION: 8.6E     LAST MODIFIED: 06/10/98   BY: *H1L5* Dana Tunstall     */
/* REVISION: 8.6E     LAST MODIFIED: 06/25/98   BY: *L034* Markus Barone     */
/* REVISION: 8.6E     LAST MODIFIED: 07/09/98   BY: *L01K* Jaydeep Parikh    */
/* REVISION: 8.6E     LAST MODIFIED: 09/11/98   BY: *L069* Jeff Wootton      */
/* REVISION: 8.6E     LAST MODIFIED: 09/14/98   BY: *L092* Steve Goeke       */
/* REVISION: 8.6E     LAST MODIFIED: 09/17/98   BY: *L09F* Jeff Wootton      */
/* REVISION: 9.0      LAST MODIFIED: 11/30/98   BY: *M00P* Jeff Wootton      */
/* REVISION: 9.0      LAST MODIFIED: 01/14/99   BY: *J37X* Prashanth Narayan */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.0      LAST MODIFIED: 04/06/99   BY: *J3CH* Hemali Desai      */
/* REVISION: 9.0      LAST MODIFIED: 04/20/99   BY: *L0CS* Brenda Milton     */
/* REVISION: 9.1      LAST MODIFIED: 07/12/99   BY: *N00D* Adam Harris       */
/* REVISION: 9.1      LAST MODIFIED: 07/20/99   BY: *L0DV* Abbas Hirkani     */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Paul Johnson      */
/* REVISION: 9.1      LAST MODIFIED: 06/19/00   BY: *N0CL* Arul Victoria     */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* REVISION: 9.1      LAST MODIFIED: 09/07/00   BY: *L136* Veena Lad         */
/* REVISION: 9.1      LAST MODIFIED: 10/19/00   BY: *N0VV* BalbeerS Rajput   */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.49        BY: Katie Hilbert     DATE: 04/01/01 ECO: *P002*     */
/* Revision: 1.50        BY: Veena Lad         DATE: 09/11/01 ECO: *M1KN*     */
/* Revision: 1.52        BY: Mercy C.          DATE: 06/24/02 ECO: *N1LK*     */
/* Revision: 1.53        BY: Manjusha Inglay   DATE: 07/29/02 ECO: *N1P4*     */
/* Revision: 1.54        BY: Hareesh V.        DATE: 09/04/02 ECO: *M209*     */
/* Revision: 1.55        BY: Jose Alex         DATE: 09/16/02 ECO: *N1RS*     */
/* Revision: 1.56        BY: Rafal Krzyminski  DATE: 02/10/03 ECO: *P0MN*     */
/* $Revision: 1.57 $  BY: Orawan S.          DATE: 05/19/03 ECO: *P0RX*      */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{cxcustom.i "ARARGL1.P"}
{gplabel.i}

{gldydef.i}
{gldynrm.i}

/* p_nr_delay INDICATES, WHETHER THE NRM SEQUNCE SHOULD BE GENERATED AT THE */
/* TIME OF PASSING GL TRASACTIONS. NO INDICATES THAT NRM SEQUENCE WILL BE  */
/* GENERATED AT THE TIME OF PASSING GL & YES INDICATES THAT NRM SEQUENCE   */
/* WILL BE GENERATED LATER. THIS FLAG IS USED TO DELAY THE LOCKING OF      */
/* nr_mstr FOR SOME FUNCTIONS WHICH TAKE TIME AT THE USER INTERFACE LEVEL. */
define input parameter reverse like mfc_logical.
define input parameter p_nr_delay like mfc_logical no-undo.

define shared variable apply2_rndmthd like rnd_rnd_mthd. /*INVOICE */
define shared variable undo_all       as logical.
define shared variable arbuff_recno   as recid.
define shared variable ar_recno       as recid.
define shared variable ard_recno      as recid.
define shared variable base_amt       like ar_amt.
define shared variable disc_amt       like ar_amt.
define shared variable gain_amt       like ar_amt.
define shared variable gltline        like glt_line.
define shared variable jrnl           like glt_ref.
define shared variable curr_amt       like glt_curr_amt.
define shared variable curr_disc      like glt_curr_amt.
define shared variable base_det_amt   like glt_amt.
/* THE JOURNAL NUMBER AS STORED IN VARIABLE ref IS REQD IN arpamtm.p,      */
/* arsbpu.p AND arsbpap.p FOR GENERATING nrm-seq-num. HENCE DEFINING IT AS */
/* A SHARED VARIABLE AND DELETING THE OLD LOCAL VARIABLE DEFINITION        */
define shared variable ref            as   character format "X(14)" no-undo.

/*hk-s-024*/ define shared variable hk_amt  like ar_amt     no-undo.

define variable tot-vtadj        as decimal.
define variable disc-pct         as decimal.
define variable vtadj            as decimal    extent 3.
define variable i                as integer.
define variable vtclass          as character  extent 3.
define variable vtcurradj        like vtadj.
define variable tot-vtcurradj    like tot-vtadj.

define variable pmt_curr         like ap_curr.
define variable vt-date          like ar_effdate.
define variable cr_ico_amt       like ar_amt.
define variable cr_ico_curr_amt  like ar_amt.
define variable ico_acct         like ar_acct.
define variable ico_sub          like ar_sub.
define variable ico_cc           like ar_cc.
define variable pmt_ex_rate      like ar_ex_rate.
define variable pmt_ex_rate2     like ar_ex_rate2.
define variable pmt_ex_ratetype  like ar_ex_ratetype.
define variable pmt_exru_seq     like ar_exru_seq.
define variable det_ex_rate      like glt_ex_rate.
define variable det_ex_rate2     like glt_ex_rate2.
define variable acctcurr         like glt_curr.
define variable exrate           like glt_ex_rate.
define variable exrate2          like glt_ex_rate2.
define variable exruseq          like glt_exru_seq.
define variable curramt          like glt_curr_amt.
define variable gen_desc         like glt_desc.
define variable det_desc         like glt_desc.
define variable mstr_desc        like glt_desc.
define variable tax_tr_type      like tx2d_tr_type   initial "19".
define variable tax_lines        like tx2d_line initial 0.
define variable post             like mfc_logical    initial true.

define variable et_ex_rate       like exr_rate       no-undo.
define variable et_ex_rate2      like exr_rate2       no-undo.
define variable l_rnd            like ar_amt          no-undo.
define variable for_curr_amt     like glt_curr_amt    no-undo.
define variable for_curr         like glt_curr        no-undo.
define variable mc-error-number  like msg_nbr         no-undo.
define variable det_ex_ratetype  like ar_ex_ratetype  no-undo.
define variable det_exru_seq     like ar_exru_seq     no-undo.
define variable l_pmt_disc       like tx2_pmt_disc    no-undo.
define variable inv_type         like tx2d_tr_type    no-undo
   initial "16".
define variable union_curr_code  like ar_curr         no-undo.
define variable is_emu_curr      like mfc_logical     no-undo.

/*VARS. inv_to_base_rate, rate2 REPLACES ar__dec01 INTRODUCED IN ETK*/
define variable inv_to_base_rate like ar_mstr.ar_ex_rate no-undo.
define variable inv_to_base_rate2 like ar_mstr.ar_ex_rate2 no-undo.
define variable comb_exch_rate like glt_ex_rate no-undo.
define variable comb_exch_rate2 like glt_ex_rate2 no-undo.
define variable l_daybooks_in_use like mfc_logical no-undo.
{&ARARGL1-P-TAG9}

define buffer armstr for ar_mstr.

{&ARARGL1-P-TAG10}
find ar_mstr where recid(ar_mstr) = ar_recno.
find ard_det where recid(ard_det) = ard_recno.

{&ARARGL1-P-TAG16}
{argetwfl.i
   ar_mstr.ar_nbr
   inv_to_base_rate
   inv_to_base_rate2}

/* SET DESCRIPTIONS FOR GENERAL LEDGER TRANSACTIONS */
{&ARARGL1-P-TAG1}
gen_desc = getTermLabel("AR_PAYMENT",24).
{&ARARGL1-P-TAG2}

{&ARARGL1-P-TAG11}
assign
   mstr_desc  = if ar_po = "" then gen_desc else ar_po
   det_desc   = mstr_desc
   et_ex_rate = (if ar_mstr.ar_ex_rate <> 1 or ar_mstr.ar_ex_rate2 <> 1
                 then ar_mstr.ar_ex_rate else inv_to_base_rate)
   et_ex_rate2 = (if ar_mstr.ar_ex_rate2 <> 1 or ar_mstr.ar_ex_rate <> 1
                  then ar_mstr.ar_ex_rate2 else inv_to_base_rate2)
   det_ex_rate = et_ex_rate
   det_ex_rate2 = et_ex_rate2
   det_ex_ratetype = ar_mstr.ar_ex_ratetype
   det_exru_seq    = ar_mstr.ar_exru_seq.

if ard_ref <> "" then do:
   find armstr where recid(armstr) = arbuff_recno.
   assign
      det_ex_rate = armstr.ar_ex_rate
      det_ex_rate2 = armstr.ar_ex_rate2
      det_ex_ratetype = armstr.ar_ex_ratetype
      det_exru_seq    = armstr.ar_exru_seq.
end.

if ard_det.ard_type = "I"      then assign inv_type = "16".
else if ard_det.ard_type = "M" then assign inv_type = "18".

assign l_pmt_disc = no.
if ard_ref <> "" and armstr.ar_curr <> base_curr then do:
   for first tx2d_det fields(tx2d_ref tx2d_tr_type tx2d_tax_code)
         where tx2d_ref     = ard_det.ard_ref and
         tx2d_tr_type = inv_type no-lock:
   end.
   if available tx2d_det then do:
      for first tx2_mstr fields(tx2_tax_code tx2_pmt_disc)
            where tx2_tax_code = tx2d_tax_code no-lock:
      end.
      if available tx2_mstr then assign l_pmt_disc = tx2_pmt_disc.
      release tx2_mstr.
      release tx2d_det.
   end.
end. /* IF ard_ref <> "" AND ... */

assign
   tot-vtadj     = 0
   tot-vtcurradj = 0.

find first gl_ctrl no-lock.

if available armstr then do:
   /* GET TAX TOTALS */
   {gprun.i ""txtotal.p"" "(input  tax_tr_type,
                            input  ard_det.ard_nbr,
                            input  ard_det.ard_ref,
                            input  tax_lines,           /* ALL LINES */
                            output tot-vtcurradj)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   /* TAX MANAGEMENT ADJUSTMENTS ARE NEGATIVE VALUES */
   if not reverse then
         tot-vtcurradj = - tot-vtcurradj.
   tot-vtadj = tot-vtcurradj.

   /* CONVERT TO PAYMENT CURRENCY */
   {gprunp.i "mcpl" "p" "mc-combine-ex-rates"
               "(input ar_mstr.ar_ex_rate,
                input  ar_mstr.ar_ex_rate2,
                input  inv_to_base_rate2,
                input  inv_to_base_rate,
                output comb_exch_rate,
                output comb_exch_rate2)"}

   {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input armstr.ar_curr,
                input  ar_mstr.ar_curr,
                input  comb_exch_rate2,
                input  comb_exch_rate,
                input  tot-vtcurradj,
                input  true,  /* ROUND */
                output tot-vtcurradj,
                output mc-error-number)"}
   if mc-error-number <> 0
   then do:
      {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
   end. /* IF mc-error-number */

   if base_curr           <> ar_mstr.ar_curr
      and ar_mstr.ar_curr <> armstr.ar_curr
   then
      assign
         det_ex_rate  = comb_exch_rate
         det_ex_rate2 = comb_exch_rate2.

   if base_curr          <> ar_mstr.ar_curr
     and ar_mstr.ar_curr =  armstr.ar_curr
   then
      assign
         det_ex_rate  = 1
         det_ex_rate2 = 1.

   if base_curr <> armstr.ar_curr then
   do:
      /* CONVERT FROM FOREIGN TO BASE CURRENCY */

      if l_pmt_disc then
         run convert_foreign_to_base
         (input armstr.ar_ex_rate,
         input armstr.ar_ex_rate2,
         input-output tot-vtadj).
      else
         run convert_foreign_to_base
         (input inv_to_base_rate,
         input inv_to_base_rate2,
         input-output tot-vtadj).

   end.
   vt-date = armstr.ar_effdate. /* invoice */
end.
else
   vt-date = ar_mstr.ar_effdate. /*check*/

assign
   curr_disc = curr_disc - tot-vtcurradj
   disc_amt  = curr_disc.
if base_curr <> ar_mstr.ar_curr
   or (ard_ref <> "" and armstr.ar_curr <> base_curr) then do:

   /* INSURE THAT SUM disc_amt AND tot-vtadj DOES NOT EXCEED  */
   /* THE TOTAL BASE DISCOUNT CAUSING A ROUNDING ERROR.       */

   if ard_ref <> "" and l_pmt_disc
   then do:
      if base_curr           <> ar_mstr.ar_curr
         and ar_mstr.ar_curr <> armstr.ar_curr
      then do:
         /* CONVERT FROM FOREIGN TO BASE CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
                      "(input ar_mstr.ar_curr,
                       input base_curr,
                       input ar_mstr.ar_ex_rate,
                       input ar_mstr.ar_ex_rate2,
                       input (curr_disc + tot-vtcurradj),
                       input true, /* ROUND */
                       output disc_amt,
                       output mc-error-number)"}.
         if mc-error-number <> 0
         then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
         end. /* IF mc-error-number */
      end. /* IF base_curr <> ar_mstr.ar_curr */
      else
      do:

         /* CONVERT FROM FOREIGN TO BASE CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
                  "(input ar_mstr.ar_curr,
                    input base_curr,
                    input inv_to_base_rate,
                    input inv_to_base_rate2,
                    input (curr_disc + tot-vtcurradj),
                    input true, /* ROUND */
                    output disc_amt,
                    output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
         end.
      end. /* ELSE IF base_curr <> ar_mstr.ar_cur */

      /* CHANGED 1ST INPUT PARMETER FROM armstr.ar_ex_rate      */
      /* TO inv_to_base_rate, 2ND INPUT PARAMETER FROM          */
      /* armstr.ar_ex_rate2 TO inv_to_base_rate2, 3RD INPUT     */
      /* PARAMETER FROM inv_to_base_rate2 TO armstr.ar_ex_rate2 */
      /* 4TH INPUT PARAMETER FROM inv_to_base_rate TO           */
      /* armstr.ar_ex_rate.                                     */

      /* COMBINE EXCHANGE RATES BEFORE CONVERTING */
      {gprunp.i "mcpl" "p" "mc-combine-ex-rates"
         "(input  inv_to_base_rate,
           input  inv_to_base_rate2,
           input  armstr.ar_ex_rate2,
           input  armstr.ar_ex_rate,
           output comb_exch_rate,
           output comb_exch_rate2)"}

      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input  armstr.ar_curr,
           input  gl_base_curr,
           input  comb_exch_rate,
           input  comb_exch_rate2,
           input  tot-vtadj,
           input  true,  /* ROUND */
           output l_rnd,
           output mc-error-number)"}

      if mc-error-number <> 0 then
      do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
      end.
      disc_amt = disc_amt - l_rnd.
   end. /* IF ard_ref <> "" and l_pmt_disc */
   else do:

      /* CONVERT TO BASE */
      /* CONVERT FROM FOREIGN TO BASE CURRENCY */
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input ar_mstr.ar_curr,
           input base_curr,
           input et_ex_rate,     /* PAYMENT TO BASE */
           input et_ex_rate2,    /* PAYMENT TO BASE */
           input disc_amt,
           input true, /* ROUND */
           output disc_amt,
           output mc-error-number)"}.
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
      end.

   end.
end.

/* SECTION MOVED FROM BELOW IN ORDER TO GET CORRECT EXCHANGE */
/* RATE BEFORE CALCULATING THE UNAPPLIED VAT AMOUNT          */
pmt_curr = ar_mstr.ar_curr.

assign pmt_ex_rate  = et_ex_rate
   pmt_ex_rate2 = et_ex_rate2
   pmt_exru_seq = ar_mstr.ar_exru_seq.

/* IF PAYING A BASE CURRENCY INVOICE, OR IF A NON-AR OR UNAPPLIED */
/* PAYMENT IS IN BASE CURRENCY, SET EXCHANGE RATE TO 1            */
if ard_ref <> "" and armstr.ar_curr = base_curr
   or ard_ref = "" and ar_mstr.ar_curr = base_curr then
   assign
      pmt_ex_rate = 1
      pmt_ex_rate2 = 1.

gain_amt = base_det_amt - base_amt - disc_amt - tot-vtadj.

if ard_ref <> "" and gain_amt <> 0 then
   run determine_gain_loss_acct.

{&ARARGL1-P-TAG3}
if ar_mstr.ar_dy_code > "" then do:
   find first dy_mstr where dy_dy_code = ar_mstr.ar_dy_code
      no-lock no-error.
   {&ARARGL1-P-TAG4}
   daybook-desc = if available dy_mstr then dy_desc else gen_desc.
end. /* if ar_mstr.ar_dy_code > "" */

/* IF BASE CURRENCY TRANSACTION AGAINST A FOREIGN CURRENCY */
/* INVOICE, THEN PASS TO GPGL.I CURRENCY AMOUNTS IN BASE   */
/* CURRENCY. ALSO, PASS CURRENCY AMOUNT IN FOREIGN FOR A/R */
/* ACCOUNT DENOMINATED IN FOREIGN CURRENCY                 */

if ard_ref <> "" then
   if armstr.ar_curr <> base_curr
   and ar_mstr.ar_curr = base_curr then
   assign
      for_curr_amt  = curr_amt + curr_disc + tot-vtcurradj
      for_curr      = armstr.ar_curr
      curr_amt      = base_amt
      curr_disc     = disc_amt
      tot-vtcurradj = tot-vtadj.
   else
   /* PASS FOREIGN CURRENCY AMOUNT IN CASE GPGLCURR.I */
   /* FINDS THE RIGHT COMBINATION TO REQUIRE IT.      */
   assign
      for_curr_amt = if reverse
                     then
                        (- ard_cur_amt)
                     else
                        ard_cur_amt
      for_curr     = armstr.ar_curr.

/* FOR PAYMENTS, ARD_CUR_AMT CONTAINS           */
/* THE PAYMENT AMOUNT IN INVOICE/MEMO CURRENCY  */

/* ASSIGNING THE VALUE OF daybooks-in-use TO LOCAL VARIABLE l_daybooks_in_use */
/* AND SETTING daybooks-in-use = no TO DELAY THE GENERATION OF nrm-seq-num.   */
/* THIS IS DONE ONLY WHEN p_nr_delay IS TRUE TO AVOID LOCKING OF nr_mstr.      */
if p_nr_delay
then
   assign
      l_daybooks_in_use = daybooks-in-use
      daybooks-in-use   = no.

/* CREATE ALL GLT_DET RECORDS FOR THIS LINE */
{&ARARGL1-P-TAG5}

{&ARARGL1-P-TAG12}
/* DELETED PARAMETER h-nrm                  */
{gprunp.i "xxarglpl" "p" "argl-create-all-glt"
           "(input disc_amt,
             input gain_amt,
             input curr_amt,
             input curr_disc,
             input ard_det.ard_acct,/* lineacct */
             input ard_det.ard_sub, /* linesub */
             input ard_det.ard_cc, /* linecc */
             input """", /* lineproject */
             input ar_mstr.ar_nbr,
             input pmt_curr,
             input tot-vtadj,
             input-output ar_mstr.ar_effdate,
             input ar_mstr.ar_batch,
             input ar_mstr.ar_acct, /* mstracct */
             input ar_mstr.ar_sub, /* mstrsub */
             input ar_mstr.ar_cc, /* mstrcc */
             input ar_mstr.ar_entity, /* crentity */
             input ard_det.ard_entity, /* drentity */
             input ar_mstr.ar_type,
             input ar_mstr.ar_var_acct,
             input ar_mstr.ar_var_sub,
             input ar_mstr.ar_var_cc,
             input ar_mstr.ar_bill,
             input pmt_ex_rate,
             input pmt_ex_rate2,
             input pmt_ex_ratetype,
             input pmt_exru_seq,
             input for_curr,
             input for_curr_amt,
             input ar_mstr.ar_dy_code,
             input daybook-desc,
             input ar_mstr.ar_disc_acct,
             input ar_mstr.ar_disc_sub,
             input ar_mstr.ar_disc_cc,
             input tot-vtcurradj,
             input 0, /* un-vt-amt */
             input 0, /* un-vt-adj */
             input 0, /* curr-un-vt-amt */
             input 0, /* curr-un-vt-adj */
             input ard_det.ard_tax_at, /* un-vt-class */
             input base_amt,
             input base_det_amt,
             input det_ex_rate,
             input det_ex_rate2,
             input-output jrnl,
             output ref,
             input mstr_desc,
             input gen_desc,
             input det_desc,
             input vtadj[1],
             input vtadj[2],
             input vtadj[3],
             input vtcurradj[1],
             input vtcurradj[2],
             input vtcurradj[3],
             input vtclass[1],
             input vtclass[2],
             input vtclass[3],
             input vt-date,
             input daybooks-in-use,
             input-output nrm-seq-num,
/*hk-s-024*/ input hk_amt,
/*hk-s-024*/ input ar_mstr.ar__chr01,
/*hk-s-024*/ input reverse
             )"}.
    
{&ARARGL1-P-TAG13}
{&ARARGL1-P-TAG6}

if tot-vtcurradj <> 0 then do:

   for first arc_ctrl
         fields (arc_sum_lvl)
         no-lock:
   end.

   /* ADDED SECOND EXCHANGE RATE, TYPE, SEQUENCE */
   /* CHANGED SEVENTH PARAMETER FROM ar_mstr.ar_ex_rate TO         */
   /* det_ex_rate, EIGHTH PARAMETER FROM ar_mstr.ar_ex_rate2 TO    */
   /* det_ex_rate2, NINTH PARAMETER FROM ar_mstr.ar_ex_ratetype TO */
   /* det_ex_ratetype, TENTH PARAMETER FROM ar_mstr.ar_exru_seq TO */
   /* det_exru_seq                                                 */
   /* CHANGED "not arc_gl_sum" TO "arc_sum_lvl" for "POST DETAIL"  */
   {&ARARGL1-P-TAG7}
   {&ARARGL1-P-TAG14}
   {gprun.i ""txglpost.p"" "(input tax_tr_type /* TRANSACTION TYPE */,
                             input ard_det.ard_nbr    /* REFERENCE */,
                             input ard_det.ard_ref       /* NUMBER */,
                             input ar_mstr.ar_curr
                                            /* TRANSACTION CURRENCY*/,
                             input ref      /* GL REFERENCE NUMBER */,
                             input ar_mstr.ar_effdate
                                                 /* EFFECTIVE DATE */,
                             input det_ex_rate
                                                  /* EXCHANGE RATE */,
                             input det_ex_rate2,
                             input det_ex_ratetype,
                             input det_exru_seq,
                             input ar_mstr.ar_batch       /* BATCH */,
                             input 'AR'                  /* MODULE */,
                             input gen_desc  /* TRANS. DESCRIPTION */,
                             input post                    /* POST */,
                             input arc_sum_lvl      /* POST DETAIL */,
                             input false            /* AUDIT TRAIL */,
                             input false       /* REPORT IN DETAIL */,
                             input ''                    /* PROJECT*/,
                             input ar_mstr.ar_type
                                               /* TYPE OF DOCUMENT */,
                             input ar_mstr.ar_ship      /* ADDRESS */,
                             input 'CHECK'       /* GLTW_WKFL TYPE */,
                             input if reverse then 1 else -1
                                                 /* POSTING SIGN */
                                    )" }
/*GUI*/ if global-beam-me-up then undo, leave.

   {&ARARGL1-P-TAG15}
   {&ARARGL1-P-TAG8}

end.

/* TO POST ROUNDING DIFFERENCE CAUSED BECAUSE OF CURRENCY CONVERSION */
/* TO THE EXCHANGE ROUNDING ACCOUNT (ELSE THE GL TRANSACTION WOULD   */
/* REMAIN UNBALANCED )                                               */

if (ar_mstr.ar_curr       <> base_curr)
   or (ard_ref            <> ""
       and armstr.ar_curr <> base_curr)
then do:
   {gprunpdf.i "mcrndpl" "p"}
   {gprunpdf.i "gpglpl"  "p"}
    run p_ex_rnd_gl_create.
end. /* IF (ar_mstr.ar_curr <> base_curr) OR ... */

/* RESET THE ORIGINAL VALUE OF THE VARIABLE daybooks-in-use */
if p_nr_delay
then
   daybooks-in-use = l_daybooks_in_use.

undo_all = no.

/*------------------------------------------------------------------*/

PROCEDURE determine_gain_loss_acct:

   /*NOTE: ar_var_acct,cc GETS DEFAULTED TO cu_rgain_acct,cc OF PAYMENT */
   /*CURRENCY (IN arpamtm.p) SINCE ORIGINATING CURRENCY NOT KNOWN THEN. */
   /*HENCE, BASED ON THE VALUE OF gain_amt, REASSIGN cu_rgain_acct, cc  */
   /*OR cu_rloss_acct, cc OF ORIGINATING CURRENCY TO ar_var_acct, cc.   */

   /*FETCH GAIN AND LOSS ACCOUNTS                      */
   /*                    SUB-ACCOUNT                   */
   /*                    CC USING ORIGINATING CURRENCY */
   for first cu_mstr
         fields(cu_rloss_acct cu_rloss_sub cu_rloss_cc
                cu_rgain_acct cu_rgain_sub cu_rgain_cc)
         where cu_mstr.cu_curr = armstr.ar_curr /*INV/MEMO CURRENCY*/
         no-lock:

      if not reverse then

         if gain_amt < 0 then
         assign
            ar_mstr.ar_var_acct = cu_mstr.cu_rgain_acct
            ar_mstr.ar_var_sub  = cu_mstr.cu_rgain_sub
            ar_mstr.ar_var_cc   = cu_mstr.cu_rgain_cc.
         else
         assign
            ar_mstr.ar_var_acct = cu_mstr.cu_rloss_acct
            ar_mstr.ar_var_sub  = cu_mstr.cu_rloss_sub
            ar_mstr.ar_var_cc   = cu_mstr.cu_rloss_cc.

      else

         if gain_amt < 0 then
         assign ar_mstr.ar_var_acct = cu_mstr.cu_rloss_acct
            ar_mstr.ar_var_sub  = cu_mstr.cu_rloss_sub
            ar_mstr.ar_var_cc   = cu_mstr.cu_rloss_cc.
         else
         assign ar_mstr.ar_var_acct = cu_mstr.cu_rgain_acct
            ar_mstr.ar_var_sub  = cu_mstr.cu_rgain_sub
            ar_mstr.ar_var_cc   = cu_mstr.cu_rgain_cc.

   end. /* FOR FIRST cu_mstr */

END PROCEDURE.

/*------------------------------------------------------------------*/

PROCEDURE convert_foreign_to_base:
   define input parameter exchange_rate  like ar_ex_rate  no-undo.
   define input parameter exchange_rate2 like ar_ex_rate2 no-undo.
   define input-output parameter tax_amount as decimal    no-undo.

   {gprunp.i "mcpl" "p" "mc-curr-conv"
      "(input armstr.ar_curr,
       input base_curr,
       input exchange_rate,
       input exchange_rate2,
       input tax_amount,
       input true, /* ROUND */
       output tax_amount,
       output mc-error-number)"}.
   if mc-error-number <> 0 then do:
      {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}.
   end.
END PROCEDURE. /* CONVERT_FOREIGN_TO_BASE */

PROCEDURE check_invoice_curr:

   /* CHECK IF THE INVOICE CURR IS AN EMU CURRENCY */
   /* AND BASE CURRENCY IS ALSO AN EMU CURRENCY  */
   union_curr_code = "".
   {gprunp.i "mcpl" "p" "mc-chk-member-curr"
      "(input  armstr.ar_curr,
        input  ar_effdate,
        output union_curr_code,
        output is_emu_curr)" }
   if not is_emu_curr then
   do:
      {gprunp.i "mcpl" "p" "mc-chk-union-curr"
         "(input  armstr.ar_curr,
           input  ar_effdate,
           output is_emu_curr)" }
   end.
   if base_curr <> union_curr_code and is_emu_curr then
   do:
      {gprunp.i "mcpl" "p" "mc-chk-member-curr"
         "(input  base_curr,
           input  ar_effdate,
           output union_curr_code,
           output is_emu_curr)" }
      if not is_emu_curr then
      do:
         {gprunp.i "mcpl" "p" "mc-chk-union-curr"
            "(input  base_curr,
              input  ar_effdate,
              output is_emu_curr)" }
      end.
   end.

END PROCEDURE. /* CHECK INVOICE CURRENCY */

/* FIND THE VARIANCE BETWEEN DEBIT/CREDIT TOTALS AND POST */
/* THE NON-ZERO VARIANCE TO EXCHANGE ROUNDING ACCOUNT     */

PROCEDURE p_ex_rnd_gl_create:

   define variable l_gltline         like glt_line            no-undo.
   define variable l_amt             like glt_amt             no-undo.
   define variable l_curramt         like glt_curr_amt        no-undo.
   define variable l_curr            like cu_curr             no-undo.
   define variable l_ex_rnd_acct     like cu_ex_rnd_acct      no-undo.
   define variable l_ex_rnd_sub      like cu_ex_rnd_sub       no-undo.
   define variable l_ex_rnd_cc       like cu_ex_rnd_cc        no-undo.
   define variable l_ex_rnd_project  like glt_project         no-undo.
   define variable l_desc            like ac_desc             no-undo.

   {gprunp.i "mcrndpl" "p" "mc-ex-rounding-diff"
      "(input ref,
        output l_gltline,
        output l_amt,
        output l_curramt
      )"}

   if l_amt <> 0
   then do:

      /* GET THE CURRENCY THAT NEEDS TO BE PASSED FOR GETTING THE  */
      /* EXCHANGE ROUNDING ACCOUNT/SUB-ACCOUNT/CC                  */
      if (ar_mstr.ar_curr         <> base_curr)
          or (ard_det.ard_ref     <> ""
              and armstr.ar_curr  <> base_curr)
      then
         if ard_det.ard_ref <> ""
         then
            l_curr = armstr.ar_curr.
         else
            l_curr = ar_mstr.ar_curr.

      /* TO GET EXCHANGE ROUNDING DETAILS FOR CREATING GL DETAIL LINE */
      {gprunp.i "mcrndpl" "p" "mc-ex-rounding-det"
         "(input  l_curr,
           output l_ex_rnd_acct,
           output l_ex_rnd_sub,
           output l_ex_rnd_cc,
           output l_ex_rnd_project,
           output l_desc
         )"}

      for first arc_ctrl
         fields (arc_sum_lvl)
         no-lock:
      end. /* FOR FIRST arc_ctrl */

      /* DELETED PARAMETER h-nrm  */
      {gprunp.i "gpglpl" "p" "gpgl-create-one-glt"
         "(input ard_det.ard_entity,
           input ard_det.ard_entity,
           input l_ex_rnd_acct,
           input l_ex_rnd_sub,
           input l_ex_rnd_cc,
           input l_ex_rnd_project,
           input l_amt,
           input l_curramt,
           input ar_mstr.ar_curr,
           input ar_mstr.ar_curr,
           input ar_mstr.ar_ex_rate,
           input ar_mstr.ar_ex_rate2,
           input ar_mstr.ar_ex_ratetype,
           input ar_mstr.ar_exru_seq,
           input ref,
           input ar_mstr.ar_effdate,
           input """",
           input l_desc,
           input mstr_desc,
           input gen_desc,
           input ar_mstr.ar_batch,
           input-output l_gltline,
           input ""AR"",
           input arc_ctrl.arc_sum_lvl,
           input false,
           input ar_mstr.ar_bill,
           input ar_mstr.ar_nbr,
           input ar_mstr.ar_type,
           input ar_mstr.ar_dy_code,
           input daybook-desc,
           input 1,
           input daybooks-in-use,
           input-output nrm-seq-num
         )"}

   end. /* IF l_amt <> 0 */

END PROCEDURE. /* PROCEDURE p_ex_rnd_gl_create */
